package kr.ac.inha.vota;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.view.Display;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.Toast;

public class TeleCallActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tele_call);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_tele_call, menu);
        return true;
    }
    
    public boolean onTouchEvent(MotionEvent event) {
		Intent intent;
		
		super.onTouchEvent(event);
		
		Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        
		Rect start = new Rect();
		start.set((int)(0.26*display.getWidth()),(int)(0.727*display.getHeight()),
				(int)(0.75*display.getWidth()),(int)(0.813*display.getHeight()));
		
		if(event.getAction() == MotionEvent.ACTION_DOWN) {
			if(start.contains((int)event.getX(),(int)event.getY())) {
			Toast.makeText(TeleCallActivity.this, "Go Telephone Main", Toast.LENGTH_SHORT).show();
			
			intent = new Intent(TeleCallActivity.this, MainActivity.class);
    		startActivity(intent);
    		finish();
			}
    		return false;
		}
		return true;	
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	if(event.getAction() == KeyEvent.ACTION_DOWN) {
    		if(keyCode == KeyEvent.KEYCODE_BACK) {
    			//Intent intent = new Intent(TeleCallActivity.this, MainActivity.class);
        		//startActivity(intent);
        		finish();
        		
        		return false;
    		}
    	}
    	
    	// TODO Auto-generated method stub
    	return super.onKeyDown(keyCode, event);
    }
}
